<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>web socket</title>
</head>
<body>
<script>
    function socketMethod() {
        if (typeof (WebSocket) == 'undefined') {
            console.log('遗憾：您的浏览器不支持WebSocket');
        } else {
            console.log('恭喜：您的浏览器支持WebSocket');
            const socket = new WebSocket('ws://192.168.0.113:8299/pdf/webSocketAdd');
            // 连接打开事件
            socket.onopen = function () {
                console.log('Socket 已打开');
                socket.send('消息发送测试(From Client)');
            };
            // 收到消息事件
            socket.onmessage = function (msg) {
                alert(msg.data);
            };
            // 连接关闭事件
            socket.onclose = function () {
                console.log('Socket已关闭');
            };
            // 发生了错误事件
            socket.onerror = function () {
                alert('Socket发生了错误');
            };
        }
    }
    socketMethod();
</script>
</body>
</html>